package com.netty.encodedecode.protol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * 解码器
 *
 * @auther: cc.ly
 * @date: 2019/1/13/013
 */

public class PersonProtolDecode extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int length = in.readInt();
        byte[] content = new byte[length];
        in.readBytes(content);
        PersonProtol person = new PersonProtol();
        person.setLength(length);
        person.setContent(content);
        out.add(person);
    }
}
